package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DTO.InsertUserAddressBO;
import com.ruoyi.common.core.domain.DTO.UpdateUserAddressBO;
import com.ruoyi.framework.web.service.UserAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

//收货地址管理
@Slf4j
@RestController
@RequestMapping("/user/address")
public class UserAddressController extends BaseController {
    @Autowired
    private UserAddressService userAddressService;

    /**
     * 添加用户地址
     */
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody @Validated InsertUserAddressBO insertUserAddressBO) {
        userAddressService.insertUserAddress(insertUserAddressBO);
        return success();
    }

    /**
     * 修改用户地址
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody @Validated UpdateUserAddressBO updateUserAddressBO) {
        userAddressService.updateUserAddress(updateUserAddressBO);
        return success();
    }

    /**
     * 查询用户地址
     */
    @GetMapping("/list/{userId}")
    public AjaxResult list(@PathVariable Long userId) {
        return success(userAddressService.selectByUserId(userId));
    }

    /**
     * 查询默认地址
     */
    @GetMapping("/default/{userId}")
    public AjaxResult defaultAddress(@PathVariable Long userId) {
        return success(userAddressService.selectDefaultByUserId(userId));
    }
}
